<template>
  <view class="order-index" ref="container">
<!--    <image src="http://mall-image.hxyrfwpt.com/static/images/promotionBg.png" mode="widthFix" class="image" /> -->
    <view class="header acea-row">
      <view class="item" @click="goAdminOrderList(0)">
        <view class="num">{{ census.orderCount.unpaidCount }}</view>
        <view>待付款</view>
      </view>
      <view class="item" @click="goAdminOrderList(1)">
        <view class="num">{{ census.orderCount.unshippedCount }}</view>
        <view>待发货</view>
      </view>
      <view class="item" @click="goAdminOrderList(2)">
        <view class="num">{{ census.orderCount.receivedCount }}</view>
        <view>待收货</view>
      </view>
      <view class="item" @click="goAdminOrderList(3)">
        <view class="num">{{ census.orderCount.evaluatedCount }}</view>
        <view>待评价</view>
      </view>
      <view class="item" @click="goAdminOrderList(4)">
        <view class="num">{{ census.orderCount.refundCount }}</view>
        <view>退款</view>
      </view>
    </view>
	
 
	
	
    <view class="wrapper" style="background-color:#ececec;">
      <view class="title">
        <text class="iconfont icon-shujutongji"></text>数据统计
      </view>
      <view class="list acea-row">
        <view class="item" @click="goStatistics({type:'price',time:'today'})">
          <view class="num">{{ census.orderTimeCount.todayPrice }}</view>
          <view>今日成交额</view>
        </view>
        <view class="item" @click="goStatistics({type:'price',time:'yesterday'})">
          <view class="num">{{ census.orderTimeCount.proPrice }}</view>
          <view>昨日成交额</view>
        </view>
        <view class="item" @click="goStatistics({type:'price',time:'month'})">
          <view class="num">{{ census.orderTimeCount.monthPrice }}</view>
          <view>本月成交额</view>
        </view>
        <view class="item" @click="goStatistics({type:'order',time:'today'})">
          <view class="num">{{ census.orderTimeCount.todayCount }}</view>
          <view>今日订单数</view>
        </view>
        <view class="item" @click="goStatistics({type:'order',time:'yesterday'})">
          <view class="num">{{ census.orderTimeCount.proCount }}</view>
          <view>昨日订单数</view>
        </view>
        <view class="item" @click="goStatistics({type:'order',time:'month'})">
          <view class="num">{{ census.orderTimeCount.monthCount }}</view>
          <view>本月订单数</view>
        </view>
      </view>
    </view>
	
	
	<view class="public-wrapper">
	  <view class="title">
	    <text class="iconfont icon-xiangxishuju"></text>{{census.merName}}
		<!-- <text style="float: right;font-size: 25rpx;color: #999;">账户明细></text> -->
	  </view> 
	  
	  <view class="nav acea-row " style="color: #2b4a39 !important;height:100rpx;justify-content:space-between;">
		  <view>
			  <view style="color: #333333;display: inline-block;margin-right: 10rpx;">可提现金额:</view>
			  <view style="font-size: 30rpx;display: inline-block;"> ¥{{census.keAmt}}</view>
		  </view>
		  <view>
			  <view  class="btn" style="" @click="submitTiXian" v-if="census.keAmt>0 ">提现</view>
			  <view  class="btn" style="background-color:#999!important;margin-left: 0 !important;"  v-else >提现</view>  
		  </view>   
	 </view>
	 </view>
	
	
	
    <view class="public-wrapper">
      <view class="title">
        <text class="iconfont icon-xiangxishuju"></text>
		详细数据
		<text style="float: right;font-size: 12px;" @click="goTransOrder">成交明细></text>
      </view>
      <view class="nav acea-row row-between-wrapper">
        <view class="data">日期</view>
        <view class="browse">订单数</view>
        <view class="turnover">成交额</view>
      </view>
      <view class="conter">
        <view
          class="item acea-row row-between-wrapper"
          v-for="(item, orderListIndex) in list"
          :key="orderListIndex"
        >
          <view class="data">{{ item.time }}</view>
          <view class="browse">{{ item.count }}</view>
          <view class="turnover">{{ item.price }}</view>
        </view>
      </view>
    </view>
    <Loading :loaded="loaded" :loading="loading"></Loading>
  </view>
</template>
<script>
import { getStatisticsInfo, getStatisticsMonth,orderTiXian } from "@/api/admin";
import Loading from "@/components/Loading";
export default {
  name: "OrderIndex",
  components: {
    Loading
  },
  props: {},
  data: function() {
    return {
      census: {
        orderCount: {},
        orderTimeCount: {},
		keAmt:0,
		merName:''
      },
      list: [],
      where: {
        page: 1,
        limit: 15
      },
      loaded: false,
      loading: false,
	  mainAccount:false //主账号 
    };
  },
  mounted: function() {
    this.getIndex();
    this.getList();
  },
  onReachBottom() {
    !this.loading && this.getList();
  },
  methods: {
    goStatistics(query) {
      this.$yrouter.push({
        path: "/pagesMer/orderAdmin/Statistics/index",
        query
      });
    },
	goTransOrder(){ //进入交易明细
	 	this.$yrouter.push({
	 	  path: "/pagesMer/orderAdmin/TransOrder/index", 
	 	});
	},
    goAdminOrderList(types) {
      this.$yrouter.push({
        path: "/pagesMer/orderAdmin/AdminOrderList/index",
        query: { types }
      });
    },
    getIndex: function() {
      var that = this;
      getStatisticsInfo().then(
        res => {
          that.census = res.data;
          that.census.unpaidCount = that.census.orderCount.unpaidCount;
        },
        err => {
          uni.showToast({
            title:
              err.msg || err.response.data.msg || err.response.data.message,
            icon: "none",
            duration: 2000
          });
        }
      );
    },
    getList: function() {
      var that = this;
      if (that.loading || that.loaded) return;
      that.loading = true;
      getStatisticsMonth(that.where).then(
        res => {
          that.loading = false;
          that.loaded = res.data.length < that.where.limit;
          that.list.push.apply(that.list, res.data);
          that.where.page = that.where.page + 1;
        },
        err => {
          uni.showToast({
            title:
              err.msg || err.response.data.msg || err.response.data.message,
            icon: "none",
            duration: 2000
          });
        },
        300
      );
    },
	submitTiXian:function(){
		var that = this;  
		
		uni.showModal({
		    title: '提示',
		    content: '确定要全部提现吗?',
		    success: function (res) {
		        if (res.confirm) {
				 uni.showLoading({
					 title: '提现中...'
				 });
				 orderTiXian(that.census.keAmt).then(res=>{ 
			        uni.hideLoading();
					
					 uni.showToast({
						 title:"提现成功",
						 icon: "none",
						 duration: 2000
					 })
					 
					 that.getIndex();
					 that.getList();
					 
				 },
				  err => {
					  uni.showToast({
						title:
						  err.msg || err.response.data.msg || err.response.data.message,
						icon: "none",
						duration: 2000
					  });
                 }, 
				 
				 ) 
				 
		        } else if (res.cancel) {
		            
		        }
		    }
		});
	}
  }
};
</script>

<style lang="less">
	.btn{
		    width: 88px;
		    height: 30px;
		    text-align: center;
		    line-height: 30px;
		    color: #333;
		    border-radius: 25px;
		    font-size: 13px;
			background-color:#fff !important;
			// margin-left:40%;
	}
	.header.acea-row{
		background-color:#fff;
	}
	.wrapper{
		background-color:#ececec;
	}
	.public-wrapper{
		background-color:#ececec;
	}
	.order-index{
		background-color:#fff;
	}
</style>